<template>
  <div>
    <mds-breadcrumb separator="/">
    <template v-for="(item, index) in levelList">
      <mds-breadcrumb-item
        v-if="index !== (levelList.length - 1)"
        :key="item.path"
        :to="item.path"
      >{{ item.meta.title }}</mds-breadcrumb-item>
      <mds-breadcrumb-item :key="item.path" v-else>{{ item.meta.title }}</mds-breadcrumb-item>
    </template>
    </mds-breadcrumb>
  </div>
</template>

<script>
export default {
  data() {
    return {
      levelList: null
    }
  },
  watch: {
    $route(route) {
      this.getBreadcrumb()
    }
  },
  created() {
    this.getBreadcrumb()
  },
  methods: {
    getBreadcrumb() {
      // only show routes with meta.title
      const matched = this.$route.matched.filter(item => item.meta && item.meta.title)
      this.levelList = matched.filter(item => item.meta && item.meta.title && item.meta.breadcrumb !== false)
    }
  }
}
</script>
